<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Sport_entity{
	var $id = 0;
	var $name ="";
	
	function __destruct() {}
	function __construct() {}
    
	function init($cmd, $input)
	{
		$ci=& get_instance();
		
		if($cmd == 'id')
		{
			$result = $ci->db->where('id',$input)->get(TBL_SPORT)->result();
		}
		else
		{
			return false;
		}
		
		if( !empty($result) )
		{
			$this->id = $result[0]->id;
			$this->name = $result[0]->name;
			
			return $this;
		}
		return false;
	}
	
	function setName($input){ $this->name=$input; }
	
	function getId(){ return $this->id; }
	function getName(){ return $this->name; }
	
	function update()
	{
		$ci=& get_instance();
		 
		$ci->db->set('name', $this->name);
		
		$ci->db->where('id', $this->id)->update(TBL_SPORT);
	}
	
	function createNewSportEntity($name){
		$ci=& get_instance();
		
		$ci->db->set('name',$name);
		$ci->db->insert(TBL_SPORT);
		
		return $ci->db->insert_id();
	}
	
	function getArrayListOfSport(){
		$ci=& get_instance();
		return $ci->db->order_by('id','desc')->get(TBL_SPORT)->result();
	}
	
	function getArrayIdAndNameOfSport(){
		$array = array();
		foreach($this->getArrayListOfSport() as $obj){
			$array[$obj->id] = $obj->name;
		}
		return $array;
	}
}
